<% session.setAttribute("title", "Review Thesis"); %> 
<%@ include file="Header.jsp"%>
<%
	String error = "";
	if (request.getParameter("submit") != null) 
		if (request.getParameter("relevance_to_topic").equals("") 
			   || request.getParameter("review_description").equals("")  
			    || request.getParameter("contributions").equals("")
			     || request.getParameter("layout_and_style").equals("")
			     	|| request.getParameter("conclusion").equals("")
			     		|| request.getParameter("recommendations").equals("")
			     			|| request.getParameter("layout_and_style").equals("")
			      				|| request.getParameter("assessment").equals("")
			      					|| session.getAttribute("username").equals("")
		){
			error = "There are errors in your upload";
		}
%>
<%
	org.jbpm.api.ProcessEngine processEngine = StaticProcessEngine.getInstance();
	TaskService taskService = processEngine.getTaskService();

	if (request.getParameter("submit") != null && error.equals("")) {
		String taskId = request.getParameter("task_id");
		Set<String> variableNames = taskService
				.getVariableNames(taskId);
		Map<String, Object> variables = taskService.getVariables(
				taskId, variableNames);
		variables.put("relevance_to_topic", request.getParameter("relevance_to_topic"));
		variables.put("review_description", request.getParameter("review_description"));
		variables.put("layout_and_style", request.getParameter("layout_and_style"));
		variables.put("contributions", request.getParameter("contributions"));
		variables.put("conclusion", request.getParameter("conclusion"));
		variables.put("recommendations", request.getParameter("recommendations"));
		variables.put("assessment", Integer.valueOf(request.getParameter("assessment")));
		taskService.completeTask(taskId, variables);

	} 

		List<Task> tasks = taskService.findPersonalTasks(session.getAttribute("username").toString());

		if (tasks.isEmpty()) {%>
			No pending reviews for you
		<% }
		
		if (request.getParameter("submit") != null && !error.equals("")) {
			%><span style="color: red;"><% out.println(error); %></span><br /><%
		}

		for (Task task : tasks) {
			String taskId = task.getId();
			Set<String> variableNames = taskService.getVariableNames(taskId);
			Map<String, Object> variables = taskService.getVariables(taskId, variableNames);
		%>
		<br />
		Proposal title:
		<%=variables.get("title")%><br />
		<form action="ReviewThesisPage.jsp">
		<table cellpadding="5" cellspacing="5">
			<tr>
				<td>Relevance to topic:</td>
				<td><input type="text" name="relevance_to_topic" /></td>
			</tr>
			<tr>
				<td>Description:</td>
				<td><input type="text" name="review_description" /></td>
			</tr>
			<tr>
				<td>Layout and style:</td>
				<td><input type="text" name="layout_and_style" /></td>
			</tr>
			<tr>
				<td>Contributions:</td>
				<td><input type="text" name="contributions" /></td>
			</tr>
			<tr>
				<td>Conclusion:</td>
				<td><input type="text" name="conclusion" /></td>
			</tr>
			<tr>
				<td>Recommendations:</td>
				<td><input type="text" name="recommendations" /></td>
			</tr>
			<tr>
				<td>Assessment:</td>
				<td><input type="text" name="assessment" /></td>
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td>
	 				<input type="hidden" name="task_id" value="<%=taskId%>" /> 
	 				<input type="submit" name="submit" value="Submit" />
	 			</td>
	 		</tr>
			<br />
		</table>
		</form>
		<% } 
%>
<%@ include file="Footer.jsp" %>